﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.COMM;
using Common;

namespace Mang24k99.Business.COMM
{
    public static class BKtCommBaseInfo
    {
        /// <summary>
        /// 新增一条记录
        /// </summary>
        /// <param name="commbase"></param>
        /// <returns></returns>
        public static bool Save(MKtCommBaseInfo commbase)
        {
            try
            {
                MKtCommBaseInfo.Create(commbase);
                return true;
            }
            catch (System.Exception e)
            {
                return false;            	
            }
            
        }
        /// <summary>
        /// 修改一条记录
        /// </summary>
        /// <param name="commbase"></param>
        /// <returns></returns>
        public static bool Update(MKtCommBaseInfo commbase)
        {
            try
            {
                MKtCommBaseInfo.Update(commbase);
                return true;
            }
            catch (System.Exception e)
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="commbase"></param>
        /// <returns></returns>
        public static bool Delete(MKtCommBaseInfo commbase)
        {
            try
            {
                MKtCommBaseInfo.Delete(commbase);
                return true;
            }
            catch (System.Exception e)
            {
                return false;
            }

        }
        /// <summary>
        ///根据参数代码返回参数值
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public  static string GetValueByCode(string code) 
        {
            return (string)MKtCommBaseInfo.GetValueByCode(code);
        }
        /// <summary>
        /// 验证编码是否有效
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string CodeValidate(string code)
        {
            string strvalidate = string.Empty;
            if (code == "")
            {
                strvalidate = "代码编码不能为空";
                return strvalidate;
            }
            //if (PageValidate.IsNumber(code) == false)
            //{
            //    strvalidate = "请输入数字类型！";
            //    return strvalidate;
            //}

            int  intReturn=MKtCommBaseInfo.SelectByProperty("FACTOR_CODE",code);
            if (intReturn!=0)
            {
                strvalidate = "代码编码不能重复！";
                return strvalidate;
            }

            strvalidate = "success";
            return strvalidate;
        }
        /// <summary>
        /// 验证编码名称有效性
        /// </summary>
        /// <param name="codename"></param>
        /// <returns></returns>
        public static string NameValidate(string codename) 
        {
            string strvalidate = string.Empty;
            if (codename == "")
            {
                strvalidate = "编码名称不能为空";
                return strvalidate;
            }

            int intReturn = MKtCommBaseInfo.SelectByProperty("FACTOR_NAME", codename);
            if (intReturn != 0)
            {
                strvalidate = "编码名称不能重复！";
                return strvalidate;
            }

            strvalidate = "success";
            return strvalidate;
        }

        public static string ValueValidate(string strValue) 
        {
            string strvalidate = string.Empty;
            if (strValue == "")
            {
                strvalidate = "参数值不能为空";
                return strvalidate;
            }

            strvalidate = "success";
            return strvalidate;
        }
        /// <summary>
        /// 返回所有可用的记录条数
        /// </summary>
        /// <returns></returns>
        public static int GetCount()
        {
            //string where = "baseinfo.IS_VALIDATE=1";
            string where = " where 1=1";
            return (int)MKtCommBaseInfo.GetCount(where);
        }
        /// <summary>
        /// 返回符合条件的记录集合
        /// </summary>
        /// <param name="start"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static IList<MKtCommBaseInfo> FindALLSliced(int start,int max)
        {
            string where = "order by ID";
            return (IList<MKtCommBaseInfo>)MKtCommBaseInfo.FindALLSliced(start, max, where);
        }

        /// <summary>
        /// 通过参数代码返回参数值
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetValue(string code)
        {
            string value = BKtCommBaseInfo.GetValueByCode(code);
            return value;
        }
        /// <summary>
        /// 通过参数代码返回格式数字的参数值，否则返回空
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetString(string code)
        {
            string value = BKtCommBaseInfo.GetValueByCode(code);
            return value;
        }


        public static MKtCommBaseInfo Find(int? ID)
        {
            return MKtCommBaseInfo.SelectByPrimaryKey(ID);
        }



    }
}
